{-# LANGUAGE TypeOperators, TypeFamilies #-}
{- |
Module      :  Model.Castelli
Description :  <optional short text displayed on contents page>
Copyright   :  (c) Sergey Sichevskiy 2013
License     :  BSD3

Maintainer  :  s.sichevskij@gmal.com
Stability   :  experimental
Portability :  portable

Модель звездных спектров.

-}

module Model.Castelli
 ( model
 , domains
 )
   where

import Types
import Model
import Data.HList

import Data.List ( sort )
import Control.Monad.Reader ( asks , forM )

type Bounds = ( Teff ::: Logg ::: Null, Teff ::: Logg ::: Null)
type Point  =   Teff ::: Logg ::: Null


{--
model_ :: Factory ( (Double ::: Double ::: Null) -> (Teff ::: Logg ::: Null), (Teff ::: Logg ::: Null) -> SED )
model_ = do

  (f,m) <- asks $ flux . modelflux

  let flux (Teff x ::: Logg y ::: Null) = f y x

      fm (x ::: y ::: Null) = (Teff teff ::: Logg logg ::: Null)
         where (logg, teff) = m (y,x)
--               theta = z --1000000 * (exp $ -(z*z))

  return (fm, flux)
--}

-- |
model :: Factory ( (Teff ::: Logg ::: Null) -> SED )
model = do

  f <- asks $ flux . modelflux

  return f

-- |
domains :: Factory [ ( Bounds, [Point] ) ]
domains = do

  ds <- asks $ Types.domain . modelflux

  return $ mkDomain `map` ds

   where
    mkDomain xy = 
      let xy' = sort xy 
          ub  = last xy'
          lb  = head xy'
      in ((lb,ub), xy')       